package com.itheima.day15.TCP.test8;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("192.168.80.1", 10009);

        // 1.上传本地文件到服务器
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("backBurner\\a\\源氏头像.jpg"));

        OutputStream os = s.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);

        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1){
            bos.write(bytes,0,len);
        }
        s.shutdownOutput();

        // 接收服务器响应
        InputStream is = s.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String str;
        while ((str = br.readLine()) != null){
            System.out.println(str);
        }

        // 释放资源
        bis.close();
        s.close();
    }
}
